package com.huazi.user.registration.servlet;

import com.alibaba.fastjson.JSON;
import com.huazi.user.registration.service.Imp.InsertGuaImpl;
import com.huazi.user.registration.service.InsertGuahaoI;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 处理挂号信息的servlet
 */
public class InsertGuaServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        InsertGuahaoI service = new InsertGuaImpl();
        String userId = req.getParameter("userid");
        String name = req.getParameter("username");
        String doctorid = req.getParameter("doctorid");
        String time = req.getParameter("time");
        //上面的获值语句是要等下调用service方法做准备
        PrintWriter out = resp.getWriter();
        String a = JSON.toJSONString(true);
        if (service.InsertGuahao(Integer.parseInt(userId), name, Integer.parseInt(doctorid), time)) {
            out.print(a);
        } else {
            out.print(false);
        }
        out.flush();//刷新缓存
        out.close();//关闭流
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
